//本js主要聚合ipcMain.on事件

const { ipcMain } = require('electron')
//获取当前窗口
let window   ;

//开启监听
exports.ipcMainOn=function (win){
    if(win){
        window = win;
    }else{
        //获取当前窗口
        window = require('electron').remote.getCurrentWindow();
    }

    windowShow()
    windowMin()
    windowMax()
    windowRestore()
    windowQuit()
    windowClose()
}


// 监听显示主窗口
function windowShow() {
    ipcMain.on('window-show', (event, arg) => {
        window.show()
    })
}

// 监听窗口最小化
function windowMin() {
    ipcMain.on('window-min', (event, arg) => {
        window.minimize()
    })
}

// 监听窗口最大化
function windowMax() {
    ipcMain.on('window-max', (event, arg) => {
        window.maximize()

    })
}

// 监听窗口还原
function windowRestore() {
    ipcMain.on('window-restore', (event, arg) => {
        window.restore()
        window.center();
    })
}

// 监听主页面关闭按钮使用退出程序
function windowQuit() {
    ipcMain.on('window-quit', (event, arg) => {
        window.close()
    })
}

// 监听关闭窗口
function windowClose() {
    ipcMain.on('window-close', (event, arg) => {
        window.close()
    })
}





